<template>

<div id="GmMenu">
  <div id="homeBar">
    <mu-appbar title="GM管理" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
    </mu-appbar>
  </div>


  <mu-list>
    <mu-list-item title="创建运营商" @click="handleCreateCa()">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <mu-icon value="arrow_forward"  slot="right"/>
    </mu-list-item>
    <mu-list-item title="创建白户账号" @click="handleCreateCaWhite()">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="运营商设置" :to="{name: 'UpdateDivision' }">
      <mu-avatar v-bind:src="this.$image.icon3" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="赠送金币" :to="{name: 'Give' }">
      <mu-avatar v-bind:src="this.$image.icon4" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="警戒值" :to="{name: 'Warning' }">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="配置个性签名玩家" :to="{name: 'Sign' }">
      <mu-avatar v-bind:src="this.$image.icon2" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="配置vip" :to="{name: 'Vip' }">
      <mu-avatar v-bind:src="this.$image.icon3" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="配置机器人" :to="{name: 'Robot' }">
      <mu-avatar v-bind:src="this.$image.icon4" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
    <mu-list-item title="增加机器人" :to="{name: 'AddRobot' }">
      <mu-avatar v-bind:src="this.$image.icon1" slot="leftAvatar"/>
      <mu-icon value="arrow_forward" slot="right"/>
    </mu-list-item>
  </mu-list>

  <el-dialog title="创建运营商" :visible.sync="dialogFormVisible">

    <el-row>
      <el-col :span="6">
        <span>运营商ID</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.carrieroperatorUid" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>设置密码</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.password" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>姓名</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.realName" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>微信号</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.wechat" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>手机号</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.phone" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>领取比例</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.division" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>领取等级</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.orgDisLevel" size="mini" ></el-input>
      </el-col>
    </el-row>

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </div>
  </el-dialog>

  <el-dialog title="创建白户账号" :visible.sync="dialogFormWhiteVisible">

    <el-row>
      <el-col :span="6">
        <span>白户账号</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.carrieroperatorUid" size="mini" ></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>白户密码</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="form.password" size="mini" ></el-input>
      </el-col>
    </el-row>

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormWhiteVisible = false">取 消</el-button>
      <el-button type="primary" @click="handleSubmitWhite">确 定</el-button>
    </div>
  </el-dialog>


</div>

</template>

<style>

#GmMenu .el-dialog {
  width: 90%
}
#GmMenu .el-row {
  margin-bottom: 16px;
}
#GmMenu .el-form-item__content {
  margin-bottom: -24px;
}
#GmMenu form.el-form {
    margin-top: -24px;
}

</style>

<script>
  export default {
    mounted () {

    },
    data () {
      return {
        form: {
          carrieroperatorUid: '',
          realName: '',
          wechat: '',
          phone: '',
          password: '',
          division: 0.30,
          orgDisLevel: 10,
          account: sessionStorage.getItem('account')
        },
        formLabelWidth: '120px',
        dialogFormVisible: false,
        dialogFormWhiteVisible: false
      }
    },
    methods: {
      handleCreateCa () {
        this.getGlobalSetUp()
        this.form.carrieroperatorUid = ''
        this.form.realName = ''
        this.form.wechat = ''
        this.form.phone = ''
        this.form.password = ''
        this.dialogFormVisible = true
      },
      handleCreateCaWhite () {
        this.dialogFormWhiteVisible = true
      },
      validate () {
        for (let item in this.form) {
          if (this.form[item].length === 0) {
            this.$message.error('请完善信息')
            return false
          }
        }
        return true
      },
      handleSubmit () {
        let that = this
        if (this.form.carrieroperatorUid === '' || this.form.carrieroperatorUid.length === 0) {
          this.$message({
            showClose: true,
            message: '请完善信息',
            type: 'warning'
          })
          return false
        }
        if (this.form.password === '' || this.form.password.length === 0) {
          this.$message({
            showClose: true,
            message: '请完善信息',
            type: 'warning'
          })
          return false
        }
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.careateCarrieroperator',
          params: this.form,
          async: false
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.$message({
              showClose: true,
              message: '创建成功',
              type: 'success'
            })
            that.dialogFormVisible = false
          } else {
            that.$message({
              showClose: true,
              message: resp.data.cause,
              type: 'warning'
            })
          }
        })
      },
      handleSubmitWhite () {
        let that = this
        if (this.form.carrieroperatorUid === '' || this.form.carrieroperatorUid.length === 0) {
          this.$message({
            showClose: true,
            message: '请完善信息',
            type: 'warning'
          })
          return false
        }

        if (this.form.password === '' || this.form.password.length === 0) {
          this.$message({
            showClose: true,
            message: '请完善信息',
            type: 'warning'
          })
          return false
        }

        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.careateCarrieroperatorWhite',
          params: this.form,
          async: false
        })
        .then(function (resp) {
          if (resp.data.status === 'success') {
            that.$message({
              showClose: true,
              message: '创建成功',
              type: 'success'
            })
            that.dialogFormWhiteVisible = false
          } else {
            that.$message({
              showClose: true,
              message: resp.data.cause,
              type: 'warning'
            })
          }
        })
      },
      getGlobalSetUp () {
        let that = this
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.getGlobalSetUp',
          async: false
        })
        .then(function (resp) {
          if (resp.data.data && resp.data.status === 'success') {
            that.form.division = resp.data.data.organizerRecRatio
            that.form.orgDisLevel = resp.data.data.organizerRecLevel
          }
        })
      }
    }
  }
</script>
